//    Copyright (C) Kherty.  All rights reserved.
using OpenLS.Core.Serialization;

namespace OpenLS.Drawing
{
    internal class TableStyleTextStyle : IOfficeXmlSerializable
    {
        private OnOffStyleType _b;
        private OfficeArtExtensionList _extLst;
        private OnOffStyleType _i;
        private const string xmlName = "tcTxStyle";
        private FontCollection font;
        private FontReference fontRef;
        private ColorBase color;

        #region IOfficeXmlSerializable Members

        public void ReadXml(ReadContext context)
        {
            using (var c = context.Read(xmlName))
            {
                _b = c.GetOptionalEnum("b", OnOffStyleType.Default);
                _i = c.GetOptionalEnum("i", OnOffStyleType.Default);
                this.font = c.ReadOptionalElementAs<FontCollection>("font");
                if (this.font == null)
                    this.fontRef = c.ReadOptionalElement<FontReference>("fontRef");
                this.color = OpenLS.Drawing.ColorBase.ReadOptionalColor(c);
                _extLst = c.ReadOptionalElement<OfficeArtExtensionList>("extLst");
            }
        }

        public void WriteXml(WriteContext context)
        {
            using (var c = context.Write(xmlName))
            {
                c.SetOptionalEnum("b", _b, OnOffStyleType.Default);
                ;
                c.SetOptionalEnum("i", _i, OnOffStyleType.Default);
                c.WriteOptionalElementAs(font, "font");
                c.WriteOptionalElement(fontRef);
                c.WriteOptionalElement(color);
                c.WriteOptionalElement(_extLst);
            }
        }

        #endregion
    }
}